<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WebSocket</title>
<script type="text/javascript">
	var  websocket;
	if ('WebSocket' in window) {  
		var  wsServer = 'ws://localhost:8080/Handler'; 
		var  websocket = new WebSocket(wsServer); 
		websocket.onopen = function (evt) { onOpen(evt) }; 
		websocket.onclose = function (evt) { onClose(evt) }; 
		websocket.onmessage = function (evt) { onMessage(evt) }; 
		websocket.onerror = function (evt) { onError(evt) }; 
	} else {  
	    alert('当前浏览器 Not support websocket')  
	} 
	
	function onOpen(evt) { 
	     console.log("Connected to WebSocket server."); 
	} 
	function onClose(evt) { 
	     console.log("Disconnected"); 
	} 
	function onMessage(evt) { 
	     console.log('Retrieved data from server: ' + evt.data); 
	} 
	function onError(evt) { 
	     console.log('Error occured: ' + evt.data); 
	}

   function showSocket(){
	   console.log("send");
		websocket.send("hello websocket server");//客户端向服务器发送消息
   }
</script>
</head>
<body>
<h1>测试websocket</h1>

<button type="button" onclick="showSocket()">Click Me!</button>
</body>